/*
 *    Copyright © OpenAtom Foundation.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package com.inspur.edp.bff.spi.event.retrieve;

import com.inspur.edp.bef.api.parameter.retrieve.RetrieveParam;
import com.inspur.edp.bff.api.exception.BffFrameworkException;
import com.inspur.edp.bff.api.exception.ErrorCodes;
import com.inspur.edp.bff.api.manager.IFSAction;
import com.inspur.edp.bff.api.manager.IFSManager;
import com.inspur.edp.bff.api.manager.IFSManagerContext;
import com.inspur.edp.bff.api.manager.context.RetrieveContext;
import com.inspur.edp.cef.entity.condition.EntityFilter;
import com.inspur.edp.cef.entity.entity.IEntityData;

import java.util.ArrayList;
import java.util.List;

public class BffRetrieveEventBroker {
    private static List<IBffRetrieveEventListener> eventLs = new ArrayList<IBffRetrieveEventListener>() {{
    }};

    private static IBffRetrieveEventListener getBffRetrieveEventListener(String className) {
        try {
            Class cls = Class.forName(className);
            IBffRetrieveEventListener listener = (IBffRetrieveEventListener) cls.newInstance();
            return listener;
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            throw new BffFrameworkException(e, ErrorCodes.BFF_FRAMEWORK_2020);
        }

    }

    public static final void fireBeforeRetrieve(IFSManager manager, List<String> dataIds, RetrieveParam retrieveParam) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }

    public static final void fireAfterRetrieve(IFSManager manager, List<IEntityData> data) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }


    public static final void fireBeforeTotalJSQAssembler(RetrieveContext retrievecontext) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }

    public static final void fireBeforeJSQAssembler(IFSAction beforeaction, RetrieveContext retrievecontext, IFSManagerContext bffcontext) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }

    public static final void fireAfterJSQAssembler(IFSManagerContext bffcontext, RetrieveContext retrievecontext) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }

    public static final void fireAfterTotalJSQAssembler(IFSManagerContext bffcontext, RetrieveContext retrievecontext, int TotalCount) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }

    public static final void fireBeforeTotalCoreRetrieve(RetrieveContext retrieveContext) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }


    public static final void fireBeforeCoreRetrieve(IFSAction queryaction, RetrieveContext retrieveContext, IFSManagerContext context) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }


    public static final void fireAfterCoreRetrieve(IFSManagerContext context, RetrieveContext retrieveContext) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }


    public static final void fireAfterTotalCoreRetrieve(IFSManagerContext context, RetrieveContext retrieveContext, int TotalCount) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }

    public static final void fireBeforeTotalJSHAssembler(RetrieveContext retrievecontext, IFSManagerContext bffcontext) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }


    public static final void fireBeforeJSHAssembler(IFSAction jshassm, RetrieveContext retrievecontext, IFSManagerContext bffcontext) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }

    public static final void fireAfteJSHAssembler(RetrieveContext retrievecontext, IFSManagerContext bffcontext) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }

    public static final void fireAfterTotalJSHAssembler(RetrieveContext retrievecontext, IFSManagerContext bffcontext, int TotalCount) {
        for (IBffRetrieveEventListener el : eventLs) {
        }
    }

    public static final void fireAfterQuery(IFSManagerContext context, EntityFilter filter, List<IEntityData> result) {
        for (IBffRetrieveEventListener el : eventLs) {
            el.afterQuery(context, filter, result);
        }
    }

    public static final void fireQueryUnnormalStop(Exception e) {
        for (IBffRetrieveEventListener el : eventLs) {
            el.queryUnnormalStop(e);
        }
    }


}
